package wk7;

public class TryCatches {

	public static void main(String[] args) {

		int[] data = { -20, 103, 0, 2032, -1 };
		
		System.out.print("Numbers in array: ");
		for (int i : data)
			System.out.print(" " + i);
		
		/*
		 * Perform a potentially unsafe computation in a loop inside a try-catch
		 */
		System.out.print("\n  Perform division with a loop inside a try block:\n   ");
		try {
			for (int i: data){
				int result = 10000/i;
				System.out.print(" " + result);
			}
		} catch (ArithmeticException ae){
			System.out.println("   Arithmetic exception!!");
		}
		System.out.println("  done with first loop!");
		
		/*
		 * Perform a potentially unsafe computation in a try-catch inside a loop
		 */
		System.out.print("\n  Perform division with try block inside a loop:\n   ");
		for (int i: data){
			try {
				int result = 10000/i;
				System.out.print(" " + result);
			} catch (ArithmeticException ae){
				System.out.print("   Arithmetic exception!!");
			}
		}
		System.out.println("\n  done with second loop!");
	}
}
